<template>
  <a-modal
    :visible="visible"
    :title="$t('menu.midTermExam')"
    :width="900"
    :bodyStyle="{
      height: '500px',
      overflow: 'auto'
    }"
    :okText="isCheck ? $t('button.SubmitReview') : $t('button.export') "
    @cancel="() => { $emit('cancel') }"
    @ok="confirm"
  >
    <detail-list :col="2">
      <detail-list-item term="学号">{{ detail.xh }}&nbsp;</detail-list-item>
      <detail-list-item term="姓名">{{ detail.xm }}&nbsp;</detail-list-item>
      <detail-list-item term="论文题目">{{ detail.lwtm }}&nbsp;</detail-list-item>
      <detail-list-item term="发表刊物">{{ detail.fbkw }}&nbsp;</detail-list-item>
      <detail-list-item term="论发表时间">{{ detail.fbsj }}&nbsp;</detail-list-item>
      <detail-list-item term="刊物级别">{{ detail.kwjbmc }} -- {{detail.qtkwjb}}&nbsp;</detail-list-item>
      <detail-list-item term="摘要">{{ detail.lwzy }}&nbsp;</detail-list-item>
      <detail-list-item term="郑州大学作为第几发表单位">{{ detail.djfbdwmc }}&nbsp;</detail-list-item>
    </detail-list>
    <detail-list v-if="!isCheck" :col="1">
      <detail-list-item term="审核结果">{{ detail.zqkhztmc }}&nbsp;</detail-list-item>
      <detail-list-item term="导师审核意见">{{ detail.dsshyj }}&nbsp;</detail-list-item>
    </detail-list>
    <a-row style="padding-bottom:16px">
        <div class="term" style="color: rgba(0, 0, 0, 0.85)">上传附件:</div>
      <a-upload
        :default-file-list="defaultFileList"
      >
      </a-upload>
    </a-row>
    <a-form v-if="isCheck" :form="form">
      <a-form-item
        label="审核结果"
        :labelCol="{span: 4,offset: 1}"
        :wrapperCol="{span: 5, offset: 1}">
        <a-select :getPopupContainer="trigger => trigger.parentNode" v-decorator="['shzt',
          {
            rules: [{ required: true, message: '请选择导师审核结果!' }],
          }]" >
          <!-- <a-select-option v-for="i in TYPE0339" :key="i.id" :value="i.code">{{ i.name }}</a-select-option> -->
          <a-select-option value="03">审核通过</a-select-option>
          <a-select-option value="04">审核不通过</a-select-option>
        </a-select>
      </a-form-item>
      <a-form-item
        label="导师经费是否划拨"
        :labelCol="{span: 4,offset: 1}"
        :wrapperCol="{span: 5, offset: 1}">
        <a-select :getPopupContainer="trigger => trigger.parentNode" v-decorator="['dsjfsfxb',
          {
            rules: [{ required: true, message: '请选择导经费是否划拨!' }],
          }]" >
          <a-select-option value="false">否</a-select-option>
          <a-select-option value="true">是</a-select-option>
        </a-select>
      </a-form-item>
      <a-form-item
        label="导师审核意见"
        :labelCol="{span: 4,offset: 1}"
        :wrapperCol="{span: 12, offset: 1}">
        <a-textarea v-decorator="['shyj',
          {
            rules: [{ required: true, message: '请输入导师审核意见!' }],
          }]" />
      </a-form-item>
    </a-form>
  </a-modal>

</template>

<script>
import { STable } from '~'
import { mapState } from 'vuex'
import DetailList from '~/tool/DetailList'
const DetailListItem = DetailList.Item

export default {
  props: ['visible', 'isCheck'],
  components: {DetailList, DetailListItem, STable},
  data () {
    return {
      form: this.$form.createForm(this),
      detail: {
        zqkhztxx: {},
        pyjhkcList: []
      },
      defaultFileList:[],
      tableData: [],
      zjcolumns: [
        {
          title: this.$t('key.name'),
          scopedSlots: { customRender: 'xm' }
        },
        {
          title: this.$t('key.zc'),
          scopedSlots: { customRender: 'zc' }
        },
        {
          title: this.$t('key.gzdw'),
          scopedSlots: { customRender: 'dw' }
        },
        {
          title: this.$t('key.zy'),
          scopedSlots: { customRender: 'zy' }
        },
        {
          title: this.$t('key.option'),
          scopedSlots: { customRender: 'action' }
        }
      ]
    }
  },
  computed: {
    ...mapState({
      TYPE0341: state => state.app['TYPE0341'],
      TYPE0339: state => state.app['TYPE0339']
    })
  },
  created () {
    this.$store.dispatch('app/setDictionary', 'TYPE0341')
    this.$store.dispatch('app/setDictionary', 'TYPE0339')
  },
  methods: {
    init(){
      this.$api.overseas.zqkhxxDetail(this.detail.id).then(res => {
          if(res.data.courseware){
            res.data.courseware.name = res.data.courseware.sourceName
            res.data.courseware.uid = res.data.courseware.id
            this.defaultFileList[0] = res.data.courseware
            this.$forceUpdate()
        }
      })
    },
    newRow () {
      let hasEdit = this.tableData.find(d => {
        return d.editable
      })
      if (hasEdit) {
        return this.$message.warning('请先完成前面的添加')
      }
      this.tableData.push({
        xm: '',
        zc: '',
        dw: '',
        action: '',
        editable: true
      })
    },
    remove (index) {
      this.tableData.splice(index, 1)
    },
    completeAdd (data) {
      if (data.xm && data.zc && data.dw && data.zy) {
        return this.$set(data, 'editable', false)
      }
      this.$message.error('请输入完整的考核专家信息')
    },
    confirm () {
      if (this.isCheck) {
        this.form.validateFields((err, values) => {
          if (err) {
            return
          }
          // if (!this.tableData.length) {
          //   this.$message.error('考核专家不能为空')
          // }
          let params = Object.assign({
            id: this.detail.id,
            khztDTOList: this.tableData
          }, values)
          // console.log(params)
          this.$api.overseas.dsshCheck(params).then(res => {
            // console.log(res)
            this.$message.success(res.msg)
            this.form.resetFields()
            this.$emit('cancel')
            this.$emit('refresh')
          })
        })
      } else {
        this.$export(`/foster/zqkhxx/exp/${this.detail.xh}`)
      }
    }
  }
}
</script>

<style>

</style>
